package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.lwj.liwanjia.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/9/9.
 */

public class PingJiaAdapter extends BaseAdapter {
    private Context context;
    private List<String> list;
    private LayoutInflater inflater;
    private int checkPosition = 0;

    public void setCheckPosition(int checkPosition) {
        this.checkPosition = checkPosition;
    }

    public PingJiaAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.pingjia_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.updataView(position);
        return convertView;
    }

    class ViewHolder {
        @BindView(R.id.pingjia_classify)
        TextView pingjiaClassify;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }

        public void updataView(final int position) {
            pingjiaClassify.setText(list.get(position));
            if (checkPosition == position) {
                pingjiaClassify.setBackgroundResource(R.drawable.pingjia_shape1);
                pingjiaClassify.setTextColor(context.getResources().getColor(R.color.colorWite));
            } else {
                pingjiaClassify.setBackgroundResource(R.drawable.pingjia_shape);
                pingjiaClassify.setTextColor(context.getResources().getColor(R.color.colorEC921A));
            }
        }
    }
}
